package org.ichow.scenegame.notis 
{
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.utils.Timer;
	import org.ichow.scenegame.events.NotiEvent;
	/**
	 * ...
	 * @author M.ichow
	 */
	public class ContinueNoti extends BaseNoti 
	{
		
		//continue
		private var __continueBtn:SimpleButton;
		private var __timeMc:MovieClip;
		private var __titleMc:MovieClip;
		private var __valueTf:TextField;
		private var _check:Timer;
		private var _value:String;
		private var _result:String;
		
		public function ContinueNoti() 
		{
		}
		
		override protected function init():void 
		{
			super.init();
			
			var skin:Sprite = _noti as Sprite;
			
			__continueBtn = skin.getChildByName("continue_btn") as SimpleButton;
			__timeMc = skin.getChildByName("time_mc") as MovieClip;
			__titleMc = skin.getChildByName("title_mc") as MovieClip;
			__valueTf = skin.getChildByName("txt") as TextField;
			__timeMc.gotoAndStop(1);
			_check = new Timer(100, 0);
			_check.addEventListener(TimerEvent.TIMER , onTimer);
		}
		
		private function onTimer(e:TimerEvent):void 
		{
			if (__timeMc.currentFrame == __timeMc.totalFrames ) {
				__timeMc.gotoAndStop(__timeMc.totalFrames);
				_check.reset();
				__continueBtn.visible = true;
			}
		}
		
		override protected function addListeners():void 
		{
			super.addListeners();
			__continueBtn.addEventListener(MouseEvent.MOUSE_UP , onContinueMouseClick);
		}
		
		override protected function removeListeners():void 
		{
			super.removeListeners();
			__continueBtn.removeEventListener(MouseEvent.MOUSE_UP , onContinueMouseClick);
		}
		
		private function onContinueMouseClick(e:MouseEvent):void 
		{
			var evt:NotiEvent = new NotiEvent(NotiEvent.NOTI_CHANGE);
			evt.status = NotiEvent.CONTINUE;
			dispatchEvent(evt);
			cancel();
		}
		
		public function get value():String 
		{
			return _value;
		}
		
		public function set value(v:String):void 
		{
			_value = v;
			__valueTf.text = _value;
			__continueBtn.visible = false;
			//start time mc
			__timeMc.gotoAndPlay(1);
			_check.start();
		}
		
		public function set result(value:String):void 
		{
			_result = value;
			trace(result);
			if (result == "lose")
				__titleMc.gotoAndStop(2);
			else
				__titleMc.gotoAndStop(1);
		}
		
		public function get result():String 
		{
			return _result;
		}
		
		
	}

}